package xyz.xuminghai.javafx_learn.scene;

import javafx.application.Application;
import javafx.scene.ImageCursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;

import java.io.File;

/**
 * 2023/1/11 11:15 星期三<br/>
 * <p>
 * 图片鼠标
 *
 * @author xuMingHai
 */
public class ImageCursorApp extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        // 文件选择器
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("选择鼠标样式图片");
        // 选择过滤器
        fileChooser.getExtensionFilters().add(
                new ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif", "*.svg")
        );

        Button button = new Button("选择鼠标图片");

        button.setOnAction(event -> {
            File file = fileChooser.showOpenDialog(primaryStage);
            System.out.println("file = " + file);
            // 选择了图片设置图片鼠标样式
            if (file != null) {
                button.setCursor(new ImageCursor(new Image(file.getAbsolutePath())));
            }
        });

        primaryStage.setTitle("ImageCursorApp");
        primaryStage.setScene(new Scene(button, 500, 300));
        primaryStage.show();

    }
}
